package com.ce.pms.common.filter;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

import org.springframework.web.util.HtmlUtils;

import com.sitechasia.webx.core.web.struts1.StrutsWebData;

/***
 * 特殊字符过滤器
 * 逻辑、功能相关描述:
 *
 * @author 燕大为 编写日期：2008-6-30
 */
public class CharacterFilter implements Filter {

	public void destroy() {
		// TODO Auto-generated method stub

	}

	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain filterChain) throws IOException, ServletException {

		HttpServletRequest req  = (HttpServletRequest) request;
		Map map = req.getParameterMap();
		Set set = map.entrySet();
		if(map!= null)
		{
			for(Iterator it = set.iterator();it.hasNext();)
			{
				Map.Entry entry = (Entry) it.next();
				if(entry.getValue() instanceof String[])
				{
					String[] values = (String[]) entry.getValue();

					for(int i = 0 ; i < values.length ; i++)
					{
						values[i] = HtmlUtils.htmlEscape(values[i]);
						values[i] = values[i].trim();
					}
					entry.setValue(values);
				}

			}
		}
		filterChain.doFilter(request, response);


		//StrutsWebData webData = StrutsWebData.getStrutsWebData();
//		req.getSession().getAttributeNames()

//		Enumeration enu = req.getAttributeNames();
//
//		for(;enu.hasMoreElements();)
//		{
//			Object obj = enu.nextElement();
//			Object obj1 = req.getAttribute(obj.toString());
//			System.out.println(obj1);
//		}



	}

	public void init(FilterConfig arg0) throws ServletException {
		// TODO Auto-generated method stub

	}

}
